Array.prototype.myReduce = function (callBack, initialValue) {
    console.log('原数组：', this)
    const arr = this
    if (arr.length == 0) {
        console.error('Reduce of empty array with no initial value')
        return;
    }
    let total = null
    let args = arguments
    function hasInitialValue(){
        if(args.length>1){
            console.log('hasInitialValue: ',initialValue)
            total = initialValue
            return true
        }
        return false
    }
    
    arr.forEach((currentValue, currentIndex) => {
        if (currentIndex > 0||(hasInitialValue()&&currentIndex==0)) {
            total = callBack(total, currentValue, currentIndex, arr)
        } else {
            total = currentValue
        }
    })
    console.log('返回值：', total)
    return total;

}
let arr0 = [1, 2, 3, 4,5]
// arr0.myReduce((total,currentValue)=>{
//     return total+currentValue
// })
let arr1 = arr0.myReduce((total, currentValue, currentIndex, arr) => {
    console.log('total:', total, 'currentValue:', currentValue, 'currentIndex:', currentIndex, arr)
    return total+currentValue
},1000)